﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Text.RegularExpressions;
using System.Net;
using com.lover.common;
using System.IO;
using com.lover.astd.common.model;
using com.lover.common.http;
using com.lover.astd.common.manager;

namespace com.lover.astd.common.partner.impl
{
    public class _51Login : LoginImplBase
    {
        public _51Login() : base() { }
        public override LoginResult login(ref List<Cookie> cookies, string verify_code = null, string extra = null)
        {
            LoginResult result = new LoginResult();
            logging();
            string loginurl = String.Format(
                "http://passport.51.com/login.5p?callback=jsonp{0}&_={0}&passport_51_jsonp=true&passport_51_user={2}&passport_51_password={2}&from=www_index_v_c&passport_auto_login=1&version=2", 
                TimeMgr.TimeStamp, _username, _password);
            HttpResult resp = TransferMgr.doGetPure(loginurl, ref cookies);
            if (resp == null) { result.StatusCode = LoginStatusCode.FailInLogin; return result; }

            string retstr = resp.getContent();

            if (!retstr.Contains("\"errno\":0"))
            {
                result.StatusCode = LoginStatusCode.FailInLogin;
                return result;
            }

            string redirecturl = String.Format("http://s{0}.astd.51.com/root/start.action", _acc.ServerId);
            processStartGame(redirecturl, result, ref cookies);
            //processRedirect(redirecturl, result, ref cookies);
            return result;
        }
    }
}
